package com.roc.template.base;

import com.github.pagehelper.PageInfo;
import org.springframework.data.domain.Page;

import java.util.List;

/**
 * @ClassName PageBean
 * @Description: TODO
 * @Author Administrator
 * @Date 2020/4/9 16 17
 * @Version V1.0
 **/
public class PageBean<T> {

    private Integer pageNum;

    private Integer pageSize;

    private Integer pages;

    private Long total;

    private List<T> list;

    public PageBean(Page<T> page) {
        this.pageNum = page.getNumber();
        this.pageSize = page.getSize();
        this.pages = page.getTotalPages();
        this.total = page.getTotalElements();
        this.list =  page.getContent();
    }

    public PageBean(PageInfo<T> page) {
        this.pageNum = page.getPageNum();
        this.pageSize = page.getSize();
        this.pages = page.getPages();
        this.total = page.getTotal();
        this.list =  page.getList();
    }

    public PageBean(List<T> list, int pageNum, int pageSize, long total) {
        this.list = list;
        this.pageNum = pageNum;
        this.pageSize = pageSize;
        this.total = total;
        this.pages = (int)(total % pageSize == 0 ? total / pageSize : total / pageSize + 1);
    }

    public Integer getPageNum() {
        return pageNum;
    }

    public void setPageNum(Integer pageNum) {
        this.pageNum = pageNum;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public Integer getPages() {
        return pages;
    }

    public void setPages(Integer pages) {
        this.pages = pages;
    }

    public Long getTotal() {
        return total;
    }

    public void setTotal(Long total) {
        this.total = total;
    }

    public List<T> getList() {
        return list;
    }

    public void setList(List<T> list) {
        this.list = list;
    }
}
